package date;

import java.util.Date;
import java.io.*;
import java.text.SimpleDateFormat;

//格式化日期
public class FormatDate {
     public static void main(String[] args) throws Exception {
          // Long time = (long) 1647179833;
          String time = "1647179833000"; //超过位数长度定义字符在转
          System.out.println("当前时间："+ format(Long.parseLong(time),"yyyy-MM-dd HH:mm:ss"));
     }


     // 传日期格式 参数默认值???
     public static String format(Date date, String strDateFormat) {
          if (strDateFormat == "") {
               strDateFormat = "yyyy-MM-dd HH:mm:ss";
          }
          SimpleDateFormat sdf = new SimpleDateFormat(strDateFormat);
          return sdf.format(date);
     }

     public static String format(Long timestrap, String strDateFormat) {
          if (strDateFormat == "") {
               strDateFormat = "yyyy-MM-dd HH:mm:ss";
          }
          Date date = new Date(timestrap);
          SimpleDateFormat sdf = new SimpleDateFormat(strDateFormat);
          return sdf.format(date);
     }

}
